package edu.xidian.onlinedocument.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;

import javax.persistence.*;
import javax.validation.constraints.Future;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import java.io.Serializable;
import java.util.Date;

@Entity
@Table(name = "user_id_token")
@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public class UserTokenData implements Serializable {
    @Id
    @GeneratedValue(strategy= GenerationType.AUTO)
    @Column(name = "user_id", updatable = false, nullable = false)
    @NotNull
    @JsonIgnore
    private Integer userId;

    @Column(name = "user_token", nullable = false)
    @NotBlank
    @Pattern(regexp = "^[0-9a-zA-Z._-]+$")
    private String userToken;

    @Temporal(TemporalType.TIMESTAMP)   //规定Date类型映射为mysql中的DateTime类型
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")    // 用于将Java后端的Date对象转换为指定格式的Json数据传递给前端，也可以指定前端格式
    @Column(name = "token_create_time")
    @Future
    @JsonIgnore
    private Date createTime;

    @OneToOne/*(cascade = CascadeType.REMOVE)     // 级联删除*/
    @JoinColumn(name = "user_id", referencedColumnName = "user_id", insertable = false, updatable = false)
    private UserData userData;
}
